const App = {
  data() {
    return {
      photo,
      page: {
        SQLSerialNumber: 'SQL_GetNewsList',
        PaginationNumber: 1,
        RowAmount: 10,
        Condition: "",
        ExtensionCondition: '',
        Total: '',
      },
      tabledata: [],
      loading: false,
      Total: 0,
      currentActivity: '',
      currentActivitySerial: '' // 新增：存储活动流水号
    }
  },
  mounted() {
    // 获取URL参数中的活动流水号
    const activitySerial = getQueryObject(window.location.href, "Party_Organization_Activity_SerialNumber");
    this.currentActivitySerial = activitySerial || '';

    // 修改查询条件
    if (activitySerial) {
      this.page.Condition = `AND Party_Organization_Activity_SerialNumber='${activitySerial}'`;
    }

    // 获取当前活动名称
    if (activitySerial) {
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableName`,
        method: "post",
        data: {
          Data: 'party_organization_activities',
          Condition: `Party_Organization_Activity_SerialNumber='${activitySerial}'`
        },
        success: (res) => {
          if (res.length > 0) {
            this.currentActivity = res[0].Activity_Name;
            this.postgetList();
          }
        }
      });
    }


  },
  methods: {
    goBack() {
      window.location.href = "./index.html";
    },

    PlanAdd(activitySerial) {
      let url = "./add.copy.html?action=Add";
      if (activitySerial) {
        url += `&activitySerial=${activitySerial}`;
      }
      window.location.href = url;
    },
    NewsAdd() {
      // const activitySerial = row.Party_Organization_Activity_SerialNumber;
      window.location.href = `../news_videos_files/news/add.html?action=Add&News_Category_SerialNumber=NC0000000000074&Party_Organization_Activity_SerialNumber=${this.currentActivitySerial}`;
    },
    postgetList(data) {
      const that = this;
      that.loading = true;
      const activitySerial = getQueryObject(window.location.href, "Party_Organization_Activity_SerialNumber");

      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableName`,
        method: "post",
        data: {
          Data: 'news',
          Condition: "Party_Organization_Activity_SerialNumber='" + activitySerial + "'"
        },
        success: (res) => {

          that.tabledata = res;
          // 打印数据验证是否包含活动流水号
          console.log("新闻数据：", res);
        },
        complete: () => {
          that.loading = false;
        }
      });
    },

    handleEdit(row) {
      let { primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
      window.location.href = "./Newsadd.html?action=Modify&nodeKey=" + row[primary_key] + "&Party_Organization_Activity_SerialNumber=" + row.Party_Organization_Activity_SerialNumber;
    },

    handleDelete(data) {
      this.$confirm('确定要删除这条新闻吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
        $.ajax({
          headers: requestHeaders(),
          url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
          method: "post",
          data: {
            Data: TableName,
            Condition: primary_key + "='" + data[primary_key] + "'"
          },
          success: (res) => {
            if (res.length === 1) {
              res[0].Row_Status = '1';
              let lJSONObject_DataSet = {};
              let lJSONObject_Table = {};
              lJSONObject_Table[TableName] = res;
              lJSONObject_DataSet['Modify'] = lJSONObject_Table;

              submitSave(lJSONObject_DataSet, (res) => {
                if (res.Status === 'success') {
                  this.$message.success('删除成功');
                  this.postgetList(this.page);
                } else {
                  this.$message.error('删除失败');
                }
              })
            } else {
              this.$message.error('删除失败');
            }
          },
          complete: (XMLHttpRequest) => {
            requestPretreatment(XMLHttpRequest)
          },
        });
      }).catch(() => { });
    }
  },
};

const { createApp } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");